<?php
$imageType = 'png';

$text = $_GET['text'];
$fontColor = split(',', $_GET['color'] ? $_GET['color'] : '0,0,0');
$bgColor = split(',', $_GET['bg'] ? $_GET['bg'] : '255,255,255');
$fontSize = $_GET['font'] ? $_GET['font'] : 12;
$padding = $_GET['padding'] ? $_GET['padding'] : 2;

$im = imagecreatetruecolor(1000, 100);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);

$size = imagettftext($im, $fontSize, 0, 0, $fontSize+10, $white, './arial.ttf', $text);
$h = $size[1]-$size[7]+$padding*2;
$w = $size[2]-$size[0]+$padding*2;
imagedestroy($im);

$im2 = imagecreatetruecolor($w, $h);
$white = imagecolorallocate($im2, $bgColor[0], $bgColor[1], $bgColor[2]);
$fontColor = imagecolorallocate($im2, $fontColor[0], $fontColor[1], $fontColor[2]);
imagefill($im2, 0, 0, $white);

imagettftext($im2, $fontSize, 0, $padding, $h-$padding, $fontColor, './arial.ttf', $text);

if ($imageType == 'png') {
  header('Content-type: image/png');
  imagepng($im2);
}
imagedestroy($im2);
?>
